import request from '../../utils/request.js'

export const getHomeTopicList = (params) => {
  return request({
    url: '/topic/home/list',
    method: 'get',
    params
  });
};

// 添加题目点赞方法
const thumbTopic = (topicId) => {
  return request({
    url: '/topic/thumb',
    method: 'POST',
    data: { topicId }
  })
}

// 添加题目收藏方法
const favourTopic = (topicId) => {
  return request({
    url: '/topic/favour',
    method: 'POST',
    data: { topicId }
  })
}

// 获取题目类型
export function getTopicTypes() {
  return request({
    url: '/topic/type/five',
    method: 'get'
  })
}

export const topic = {

    // 获取每日一题列表
    getDailyTopicList() {
        return request({
            url: `/topic/daily`,
            method: 'get'
        })
    },

    // 获取题库题目列表
    getTopicListByBankId(bankId) {
        return request({
            url: `/topic/bank/${bankId}`,
            method: 'get'
        })
    },

    // 获取题目详情
    getTopicDetail(topicId) {
        return request({
            url: `/topic/info/${topicId}`,
            method: 'get'
        })
    },

    // 提交题目答案
    submitTopicAnswer(topicId, answer) {
        return request({
            url: `/topic/${topicId}/submit`,
            method: 'post',
            data: answer
        })
    },

    // 获取提交历史
    getSubmissionHistory(topicId) {
        return request({
            url: `/topic/${topicId}/submissions`,
            method: 'get'
        })
    },

    // 获取热力图数据
    getHeatmap() {
        return request({
            url: '/topic/heatmap',
            method: 'get'
        })
    },

    // 添加测试SQL的方法
    testTopic: (data) => {
        return request({
            url: '/topic/test',
            method: 'post',
            data
        });
    },

    // 添加提交接口
    runTopic: (data) => {
        return request({
            url: '/topic/submit',
            method: 'post',
            data
        });
    },

    // 获取提交记录列表
    getSubmitLogs(topicId) {
        return request({
            url: '/submitLog/list',
            method: 'get',
            params: { topicId }
        })
    },

    // 添加获取题解的方法
    getExplain(id) {
        return request({
            url: `/topic/explain/${id}`,
            method: 'get'
        })
    },

    // 添加获取排行榜数据的方法
    getRankList(type) {
        return request({
            url: `/topic/explain/rank`,
            method: 'get',
            params: { type }
        })
    },

    // 获取解题进度
    getProgress() {
        return request({
            url: `/topic/explain/progress`,
            method: 'get'
        })
    },

    // 获取做题记录
    getSubmitLog() {
        return request({
            url: '/topic/submit/log',
            method: 'get'
        })
    },

    // 获取讨论记录
    getReplyLog() {
        return request({
            url: '/topic/reply/log',
            method: 'get'
        })
    },

    // 获取连胜次数
    getStreak() {
        return request({
            url: '/topic/heatmap/streak',
            method: 'get'
        })
    },

    thumbTopic,
    favourTopic

}

// 移除其他可能的导出
